package com.yuhs.zixing.study.design.pattern.dp002.structural.s007.proxy.p005;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * @description:
 * @author: yuhs
 * @date: 2022/5/2 9:11 PM
 */
public class Client005 {
    public static void main(String[] args) throws Throwable {
        //定义一个痴迷的玩家
        IGamePlayer005 player = new GamePlayer005("张三");
        //定义一个handler
        InvocationHandler handler = new GamePlayIH005(player);
        //开始打游戏，记下时间戳
        System.out.println("开始时间是：2009-8-25 10:45");
        //获得类的class loader
        ClassLoader cl = player.getClass().getClassLoader();
        //动态产生一个代理者
        IGamePlayer005 proxy = (IGamePlayer005) Proxy.newProxyInstance(cl, new Class[]{IGamePlayer005.class}, handler);
        //登录
        proxy.login("zhangSan", "password");
        //开始杀怪
        proxy.killBoss();
        //升级
        proxy.upgrade();
        //记录结束游戏时间
        System.out.println("结束时间是：2009-8-26 03:00");
    }
}
